﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NRemedy
{
    /// <summary>
    /// Id      AR Type             .NET Type
    /// 2u      IntegerField        Int32
    /// 3u      RealField           Double
    /// 4u      CharacterField      String
    /// 5u      DiaryField          BMC.ARSystem.DiaryList
    /// 6u/8u   SelectionField      Int32??
    /// 7u      DateTimeField       DateTime
    /// 10u     DecimalField        Decimal
    /// 11u     AttachmentField     BMC.ARSystem.Attachment
    /// 12u     CurrencyField       BMC.ARSystem.CurrencyValue
    /// 13u     DateOnlyField       BMC.ARSystem.DateValue
    /// 14u     TimeOnlyField       BMC.ARSystem.TimeOfDayValue
    /// </summary>
    public class ARDataTypeConvert
    {
        public static Type MappingARType(string atTypeName)
        {
            return MappingARType((ARType)Enum.Parse(typeof(ARType), atTypeName));
        }

        public static Type MappingARType(ARType arType)
        {
            return MappingARType((uint)arType);
        }

        public static Type MappingARType(uint arTypeID)
        {
            switch(arTypeID)
            {
                case 2u:return typeof(Int32);
                case 3u:return typeof(Double);
                case 4u:return typeof(String);
                case 5u: return typeof(BMC.ARSystem.DiaryList);
                case 6u: return typeof(Int32);//?
                case 8u: return typeof(Int32);//?
                case 7u:return typeof(DateTime);
                case 10u:return typeof(Decimal);
                case 11u: return typeof(BMC.ARSystem.Attachment);
                case 12u: return typeof(BMC.ARSystem.CurrencyValue);
                case 13u: return typeof(BMC.ARSystem.DateValue);
                case 14u: return typeof(BMC.ARSystem.TimeOfDayValue);
                default: throw new InvalidCastException(string.Format("{0} is not supported data field type", arTypeID));
            }
 
        }
    }
}
